package tool.library;

import android.util.Patterns;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by youyi on 2014/12/17.
 */
public class TextFormTool {
    public static boolean checkEmailForm(final String email){
        Pattern pattern= Patterns.EMAIL_ADDRESS;
        Matcher matcher=pattern.matcher(email);
        return matcher.find();
    }
    public static boolean checkPhoneForm(final String phone){
        Pattern pattern= Pattern.compile("^1[0-9]{10}$");
        Matcher matcher=pattern.matcher(phone);
        return matcher.find();
    }
    public static boolean checkTelephoneForm(final String telephone)
    {
        Pattern pattern= Pattern.compile("^(?:(?:0\\d{2,3}[- ]?[1-9]\\d{6,7})|(?:[48]00[- ]?[1-9]\\d{6}))$");
        Matcher matcher=pattern.matcher(telephone);
        return matcher.find();
    }
    public static boolean isInteger(final String str)
    {
        Pattern pattern= Pattern.compile("^\\d+$");
        Matcher matcher=pattern.matcher(str);
        return matcher.find();
    }
    public static boolean isDouble(final String str)
    {
        Pattern pattern= Pattern.compile("^[+]?\\d+(\\.\\d+)?$");
        Matcher matcher=pattern.matcher(str);
        return matcher.find();
    }
}
